package com.lxq.LeetCode.divide;

public class Solution {
    public static void main(String[] args) {
        System.out.println(divide(Integer.MIN_VALUE, 1));
    }

    public static int divide(int dividend, int divisor) {
        if (dividend == 0){
            return 0;
        }else if (divisor == 1){
            return dividend;
        }
        long time = 0;
        int symbol = 1;
        if (dividend < 0 && divisor > 0) {
            symbol = -1;
            divisor = -divisor;
        } else if (dividend > 0 && divisor < 0) {
            symbol = -1;
            dividend = -dividend;
        }else if (dividend > 0 && divisor > 0){
            divisor = -divisor;
            dividend = -dividend;
        }
        while (dividend <= divisor) {
            dividend -= divisor;
            time++;
        }

        if (time > Integer.MAX_VALUE) {
            return Integer.MAX_VALUE;
        }


        return symbol == -1 ? (int) -time : (int) time;
    }
}
